﻿using MediatR;
using PublicClass;
using S.Eartag.Domain;
using S.Eartag.Domain.Model;
using S.Eartag.Infrastructure.Interface;
using S.Eartag.Read.API.Application.Command.SheepFileConditionCommand;

namespace S.Eartag.Read.API.Application.CommandHandlers.SheepFileConditionCommandHandler
{
    public class SheepFileConditionbreedCommandHandler : IRequestHandler<SheepFileConditionbreedCommand, DTO>
    {
        private readonly ISheepFileRepository sheepFileRepository;

        public SheepFileConditionbreedCommandHandler(ISheepFileRepository sheepFileRepository)
        {
            this.sheepFileRepository = sheepFileRepository;
        }

        public async Task<DTO> Handle(SheepFileConditionbreedCommand request, CancellationToken cancellationToken)
        {
            var res = sheepFileRepository.GetValues(x => x.EarNumber == request.EarNumber).Result.FirstOrDefault();

            DTO dTO = new DTO()
            {
                breed = res.breed.ToString(),
            };
            return  dTO;
        }
    }
}
